import calendar
import pandas as pd
from collections import Counter
import re
import time

df = pd.read_excel("./data.xlsx", sheet_name = "Sheet6")
# ============================ Initialize ============================
# print(df.head() )
# writer_excel = pd.ExcelWriter("./output.xlsx")

# df_source_title = df.value_counts(['Source_Title'])
# df_research_areas = df.value_counts(['Research_Areas'])
# df_source_title.to_excel(writer_excel, sheet_name = 'source_title', index = None, header = True)
# df_research_areas.to_excel(writer_excel, sheet_name = 'research_areas', index = None, header = True)
# print(df_source_title)
# ============================ Initialize ============================


# ============================ Month Process ============================
# publication_date = list(df['Publication_Date'] )
# months = {"jan" : "1", "feb": "2" ,"mar":"3","apr":"4","may":"5", "jun": "6", "jul" : "7", "aug" : "8", "sep":"9", "oct" : "10", "nov" : "11", "dec" : "12"}
# for idx, date_ in  enumerate(publication_date):
#     if isinstance(date_, str):
#         cur_m = date_[:3].lower()
#         if cur_m not in months:
#             publication_date[idx] = ""
#         else:
#             publication_date[idx] = months[cur_m]
#         pass
#     elif isinstance(date_, float):
#         publication_date[idx] = ""
#     else:
#         publication_date[idx] = publication_date[idx].strftime("%m").lstrip('0') 
# df['Publication_Date'] = publication_date

# ============================ Month Process ============================


# ============================ Author ============================

# author = []
# for idx, authors in enumerate(df['Author_Full_Names']):
#     authors_list = authors.split(";")
#     authors_list = list(map(lambda x : x.lower(), authors_list) )
#     author = author + authors_list

# author_counter = Counter(author)
# authors_ = []
# times_ = []
# for auth in author_counter:
#     authors_.append(auth)
#     times_.append(author_counter[auth])
# df_auth_times = pd.DataFrame({"Author" : authors_, "Occurrence" : times_})
# df_auth_times.to_excel(writer_excel, sheet_name = 'Author_occurrence', index = None, header = True)
# writer_excel.save()


# print(sorted(author))
# dt_authors = pd.DataFrame({"Authors" : author})
# dt_authors.to_csv("./authors.csv", index = None)


# ============================ Author ============================

# ============================ research areas ============================
# 统计文章是否在多个涉及多个领域
research_Areas = df['Research_Areas']
# appear_times = list(map(lambda x : x.count(";"), research_Areas) )
# result = Counter(appear_times)
# print(result)
df_research_areas = pd.read_excel("./output.xlsx", sheet_name = "Research_Areas")
ArtsHumanities = df_research_areas['Arts & Humanities']
medicine = df_research_areas["Life Sciences & Biomedicine"]
PhysicalSciences = df_research_areas["Physical Sciences"]
SocialSciences = df_research_areas["Social Sciences"]
Technology = df_research_areas["Technology"]
print(Technology)
